package com.ruoyi.project.data.metallographic.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.data.metallographic.domain.SytMetallographicSpectrumInfo;
import com.ruoyi.project.data.metallographic.service.ISytMetallographicSpectrumInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 金相图谱信息Controller
 * 
 * @author ruoyi
 * @date 2024-04-27
 */
@Controller
@RequestMapping("/data/metallographic")
public class SytMetallographicSpectrumInfoController extends BaseController
{
    private String prefix = "data/metallographic";

    @Autowired
    private ISytMetallographicSpectrumInfoService sytMetallographicSpectrumInfoService;

    @RequiresPermissions("data:metallographic:view")
    @GetMapping()
    public String metallographic()
    {
        return prefix + "/metallographic";
    }

    /**
     * 查询金相图谱信息列表
     */
    @RequiresPermissions("data:metallographic:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SytMetallographicSpectrumInfo sytMetallographicSpectrumInfo)
    {
        startPage();
        List<SytMetallographicSpectrumInfo> list = sytMetallographicSpectrumInfoService.selectSytMetallographicSpectrumInfoList(sytMetallographicSpectrumInfo);
        return getDataTable(list);
    }

    /**
     * 导出金相图谱信息列表
     */
    @RequiresPermissions("data:metallographic:export")
    @Log(title = "金相图谱信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SytMetallographicSpectrumInfo sytMetallographicSpectrumInfo)
    {
        List<SytMetallographicSpectrumInfo> list = sytMetallographicSpectrumInfoService.selectSytMetallographicSpectrumInfoList(sytMetallographicSpectrumInfo);
        ExcelUtil<SytMetallographicSpectrumInfo> util = new ExcelUtil<SytMetallographicSpectrumInfo>(SytMetallographicSpectrumInfo.class);
        return util.exportExcel(list, "金相图谱信息数据");
    }

    /**
     * 新增金相图谱信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存金相图谱信息
     */
    @RequiresPermissions("data:metallographic:add")
    @Log(title = "金相图谱信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SytMetallographicSpectrumInfo sytMetallographicSpectrumInfo)
    {
        return toAjax(sytMetallographicSpectrumInfoService.insertSytMetallographicSpectrumInfo(sytMetallographicSpectrumInfo));
    }

    /**
     * 修改金相图谱信息
     */
    @RequiresPermissions("data:metallographic:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SytMetallographicSpectrumInfo sytMetallographicSpectrumInfo = sytMetallographicSpectrumInfoService.selectSytMetallographicSpectrumInfoById(id);
        mmap.put("sytMetallographicSpectrumInfo", sytMetallographicSpectrumInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存金相图谱信息
     */
    @RequiresPermissions("data:metallographic:edit")
    @Log(title = "金相图谱信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SytMetallographicSpectrumInfo sytMetallographicSpectrumInfo)
    {
        return toAjax(sytMetallographicSpectrumInfoService.updateSytMetallographicSpectrumInfo(sytMetallographicSpectrumInfo));
    }

    /**
     * 删除金相图谱信息
     */
    @RequiresPermissions("data:metallographic:remove")
    @Log(title = "金相图谱信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sytMetallographicSpectrumInfoService.deleteSytMetallographicSpectrumInfoByIds(ids));
    }
}
